﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data;

namespace GSManager
{
    public class LoaiSanPham
    {
        private string _MaLoaiSanPham;
        private string _TenLoaiSanPham;
        public string MaLoaiSanPham
        {
            get { return _MaLoaiSanPham; }
            set { _MaLoaiSanPham = value; }
                
        }
        public string TenLoaiSanPham
        {
            get { return _TenLoaiSanPham; }
            set { _TenLoaiSanPham = value;}
        }
        public void ThemLoaiSanPham()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "insert into LOAISANPHAM values(?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@MaLoaiSanPham", OleDbType.VarChar);
            cmd.Parameters.Add("@TenLoaiSanPham", OleDbType.VarWChar);
            cmd.Parameters[0].Value = MaLoaiSanPham;
            cmd.Parameters[1].Value = TenLoaiSanPham;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
     /*   public List<LoaiSanPham> LayDanhSach()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from LOAISANPHAM ";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            List<LoaiSanPham> list = new List<LoaiSanPham>() ;
            LoaiSanPham loaisanpham;
            while (r.Read())
            {
                loaisanpham = new LoaiSanPham();
                loaisanpham.MaLoaiSanPham = (string)r[0];
                loaisanpham.TenLoaiSanPham = (string)r[1];
                list.Add(loaisanpham);
            }
            r.Close();
            connect.Close();
            return list;
        }*/
        public DataSet LayDanhSach()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from LOAISANPHAM ";
            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, connect);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "LOAISANPHAM");
            connect.Close();
            return ds;
        }
        public bool KiemTraMaLoaiSP()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select MaLoaiSanPham from LOAISANPHAM where MaLoaiSanPham=?";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@MaLoaiSanPham", OleDbType.VarChar);
            
            cmd.Parameters[0].Value = MaLoaiSanPham;
            OleDbDataReader r = cmd.ExecuteReader();
            bool kq =r.Read();
            return kq;
        }
        public bool KiemTraTenLoaiSP()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select MaLoaiSanPham from LOAISANPHAM where TenLoaiSanPham=?";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@TenLoaiSanPham", OleDbType.VarWChar);
            cmd.Parameters[0].Value = TenLoaiSanPham;
            OleDbDataReader r = cmd.ExecuteReader();
            bool kq = r.Read();
            return kq;
        }
    }
}
